package com.smartthinking.dive;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.Dictionary;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.text.method.ScrollingMovementMethod;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class EventosDetalles extends Activity{

	public ListView listView3;
	TextView pagweb, tel3, tel4, tel5, tel6, correo1, desc1, textoidcard, texto; 
	String eve_descripcion, eve_poster, eve_mail, eve_facebook, eve_twitter, eve_www, eve_tel, eve_tel2, eve_tel3, eve_tel4, eve_lat, eve_lng, 
	eve_pdf, eve_nombre, eve_fec_fin, eve_fec_ini, eve_lugar, eve_contacto,eve_contacto2, eve_publicado, eve_lugar_en, eve_linkedin, eve_youtube
	,eve_hora_ini, eve_hora_fin, eve_activo, eve_direccion, eve_colonia, eve_municipio, eve_cp, eve_proveedores,edo_cve;
	Context context;
	TableRow tableRow1, tableRow2, tableRow3;
	ImageView imagen1, btnpdfeventos, btnfacebookeve, btntwittereve;
	String[] datos;
	TableLayout tablasocialevento, tabladatosevento;
	RelativeLayout detallesevento;
	private static final String HTTPS = "https://";
	private static final String HTTP = "http://";
	private Dictionary dic;
	Button calendar, btn, home;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.tarjeta_informacion_evento);
		context = this;

		pagweb = (TextView) findViewById(R.id.textViewpagweb);
		tel3 = (TextView) findViewById(R.id.textViewtel3);
		tel4 = (TextView) findViewById(R.id.textViewtel4);
		tel5 = (TextView) findViewById(R.id.textViewtel5);
		tel6 = (TextView) findViewById(R.id.textViewtel6);
		correo1 = (TextView) findViewById(R.id.textViewcorreo1);
		desc1 = (TextView) findViewById(R.id.textViewtexteven);
		tableRow1 = (TableRow) findViewById(R.id.tableRow1);
		tableRow2 = (TableRow) findViewById(R.id.tableRow2);
		tableRow3 = (TableRow) findViewById(R.id.tableRow3);
		imagen1 = (ImageView) findViewById(R.id.imageViewbanner);
		btnfacebookeve = (ImageView) findViewById(R.id.imageView6);
		btntwittereve = (ImageView) findViewById(R.id.imageView7);
		btnpdfeventos = (ImageView) findViewById(R.id.imageView8);
		tablasocialevento = (TableLayout) findViewById(R.id.tableLayoutredsocialevento);
		tabladatosevento = (TableLayout) findViewById(R.id.tableLayoutdetallesevento);
		detallesevento = (RelativeLayout) findViewById(R.id.relativeLayoutlogoevento);
		calendar = (Button) findViewById(R.id.buttoncalendar);
		texto = (TextView) findViewById(R.id.txttext);
		home = (Button) findViewById(R.id.btnHOME);
		home.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0)
			{
				finish();
				Intent intent1 = new Intent(EventosDetalles.this,Principal.class);
				intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
				startActivity(intent1);
				
			}
		});

		int tam = Utilities.getScreenSize2(EventosDetalles.this);
		if(tam == 1){
			RelativeLayout.LayoutParams params = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
			params.setMargins(20, 20, 10, 0);
			//			params.setMargins(left, top, right, bottom)
			detallesevento.setLayoutParams(params);

			RelativeLayout.LayoutParams params1 = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
			params1.setMargins(0, 10, 0, 0);
			params1.addRule(RelativeLayout.BELOW, R.id.relativeLayoutlogoevento);
			tabladatosevento.setLayoutParams(params1);

			RelativeLayout.LayoutParams params2 = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
			params2.setMargins(30, 8, 0, 0);
			params2.addRule(RelativeLayout.BELOW, R.id.tableLayoutdetallesevento);
			tablasocialevento.setLayoutParams(params2);


		}



		if(tam == 2){
			RelativeLayout.LayoutParams params = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
			params.setMargins(30, 50, 20, 0);
			//			params.setMargins(left, top, right, bottom)
			detallesevento.setLayoutParams(params);

			RelativeLayout.LayoutParams params1 = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
			
			
			int widthOfscreen =0;
			int heightOfScreen = 0;
			DisplayMetrics dm = new DisplayMetrics();
			        try {
			            ((Activity) context).getWindowManager().getDefaultDisplay()
			                    .getMetrics(dm);
			        } catch (Exception ex) {
			        }
			         widthOfscreen  = dm.widthPixels;
			heightOfScreen  = dm.heightPixels;
			
//			Toast toast1 =
//		            Toast.makeText(getApplicationContext(),
//		                    "Getting Width: "+ widthOfscreen+ "Getting Height: " + heightOfScreen, Toast.LENGTH_LONG);
//		        toast1.show();
			Log.d("Tag", "Getting Width >> " + widthOfscreen);
			Log.d("Tag", "Getting Height >> " + heightOfScreen);
			
			if(heightOfScreen>=480 && heightOfScreen<=800){
				
				params1.setMargins(0, 45, 0, 0);
				params1.addRule(RelativeLayout.BELOW, R.id.relativeLayoutlogoevento);
				tabladatosevento.setLayoutParams(params1);
				
			}else if(heightOfScreen>=800 && heightOfScreen<=880){
			
				params1.setMargins(0, 75, 0, 0);
				params1.addRule(RelativeLayout.BELOW, R.id.relativeLayoutlogoevento);
				tabladatosevento.setLayoutParams(params1);
				
			}else if(heightOfScreen>=880){
				
				params1.setMargins(0, 95, 0, 0);
				params1.addRule(RelativeLayout.BELOW, R.id.relativeLayoutlogoevento);
				tabladatosevento.setLayoutParams(params1);
				
			}
			
			
//			params1.setMargins(0, 45, 0, 0);
//			params1.addRule(RelativeLayout.BELOW, R.id.relativeLayoutlogoevento);
//			tabladatosevento.setLayoutParams(params1);

			RelativeLayout.LayoutParams params2 = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
//			params2.setMargins(50, 35, 0, 0);
//			params2.addRule(RelativeLayout.BELOW, R.id.tableLayoutdetallesevento);
			params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
			tablasocialevento.setPadding(35, 0, 0, 31);
			tablasocialevento.setLayoutParams(params2);

		}



		if(tam == 3){
			RelativeLayout.LayoutParams params = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
			params.setMargins(60, 80, 40, 0);
			//			params.setMargins(left, top, right, bottom)
			detallesevento.setLayoutParams(params);

			RelativeLayout.LayoutParams params1 = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
			params1.setMargins(25, 180, 0, 0);
			params1.addRule(RelativeLayout.BELOW, R.id.relativeLayoutlogoevento);
			tabladatosevento.setLayoutParams(params1);

			RelativeLayout.LayoutParams params2 = 
					new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
			params2.setMargins(100, 105, 0, 0);
			params2.addRule(RelativeLayout.BELOW, R.id.tableLayoutdetallesevento);
			tablasocialevento.setLayoutParams(params2);


		}



		Bundle extras1 = getIntent().getExtras();
		eve_descripcion = extras1.getString("query19");
		eve_poster = extras1.getString("query20");
		eve_mail = extras1.getString("query21");
		Log.i("eve_mail", "eve_mail "+eve_mail);
		eve_facebook = extras1.getString("query22");
		eve_twitter = extras1.getString("query23");
		eve_www = extras1.getString("query24");
		Log.i("eve_www", "eve_www "+eve_www);
		eve_tel = extras1.getString("query25");
		eve_tel2 = extras1.getString("query26");
		eve_tel3 = extras1.getString("query27");
		eve_tel4 = extras1.getString("query28");
		eve_lat = extras1.getString("query29");
		eve_lng = extras1.getString("query30");
		eve_pdf = extras1.getString("query31");
		eve_nombre = extras1.getString("query32");
		eve_fec_ini = extras1.getString("query33");
		eve_fec_fin = extras1.getString("query34");
		eve_municipio = extras1.getString("query46");


		eve_lugar = extras1.getString("query50");

		Log.i("LUGAR",""+eve_lugar);
		eve_contacto = extras1.getString("query37");
		eve_contacto2 = extras1.getString("query38");
		eve_activo = extras1.getString("query39");
		//		eve_linkedin = extras1.getString("query40");
		//		eve_youtube = extras1.getString("query41");
		eve_hora_ini = extras1.getString("query42");
		eve_hora_fin = extras1.getString("query43");
		eve_direccion = extras1.getString("query44");
		eve_colonia = extras1.getString("query45");
		eve_municipio = extras1.getString("query46");
		eve_cp = extras1.getString("query47");
//		eve_proveedores,eve_contacto,eve_contacto2,edo_cve
		eve_proveedores = extras1.getString("query48");
		edo_cve = extras1.getString("query49");

		//		if(tel3.getText().toString().equals("")||tel3.getText().toString().equals("null")||tel3.getText().toString().equals(null)){
		//
		//			tel3.setVisibility(View.GONE);
		//		}else{
		tel3.setText(eve_tel+"	   ");
		//		}
		//
		//		if(tel4.getText().toString().equals("")||tel4.getText().toString().equals("null")||tel4.getText().toString().equals(null)){
		//
		//			tel4.setVisibility(View.GONE);
		//		}else{
		tel4.setText(eve_tel2+"	   ");
		//		}
		//
		//		if(tel5.getText().toString().equals("")||tel5.getText().toString().equals("null")||tel5.getText().toString().equals(null)){
		//
		//			tel5.setVisibility(View.GONE);
		//		}else{
		tel5.setText(eve_tel3+"	   ");
		//		}
		//
		//
		//		if(tel6.getText().toString().equals("")||tel6.getText().toString().equals("null")||tel6.getText().toString().equals(null)){
		//
		//			tel6.setVisibility(View.GONE);
		//		}else{
		tel6.setText(eve_tel4);
		//		}

		
		String edo = "";
		
		if(edo_cve.equals("1")){
			edo="AGUASCALIENTES";
		}
		if(edo_cve.equals("2")){
			edo="BAJA CALIFORNIA";
		}
		if(edo_cve.equals("3")){
			edo="BAJA CALIFORNIA SUR";
		}
		if(edo_cve.equals("4")){
			edo="CAMPECHE";
		}
		if(edo_cve.equals("5")){
			edo="CHIAPAS";
		}
		if(edo_cve.equals("6")){
			edo="CHIHUAHUA";
		}
		
		if(edo_cve.equals("7")){
			edo="COAHUILA";
		}
		
		if(edo_cve.equals("8")){
			edo="COLIMA";
		}
		
		if(edo_cve.equals("9")){
			edo="DISTRITO FEDERAL";
		}
		
		if(edo_cve.equals("10")){
			edo="DURANGO";
		}

		if(edo_cve.equals("11")){
			edo="ESTADO DE MEXICO";
		}
		
		if(edo_cve.equals("12")){
			edo="GUANAJUATO";
		}

		if(edo_cve.equals("13")){
			edo="GUERRERO";
		}

		if(edo_cve.equals("14")){
			edo="HIDALGO";
		}

		if(edo_cve.equals("15")){
			edo="JALISCO";
		}

		if(edo_cve.equals("16")){
			edo="MICHOACAN";
		}

		if(edo_cve.equals("17")){
			edo="MORELOS";
		}

		if(edo_cve.equals("18")){
			edo="NAYARIT";
		}

		if(edo_cve.equals("19")){
			edo="NUEVO LEON";
		}

		if(edo_cve.equals("20")){
			edo="OAXACA";
		}
		
		if(edo_cve.equals("21")){
			edo="PUEBLA";
		}

		if(edo_cve.equals("22")){
			edo="QUERETARO";
		}

		if(edo_cve.equals("23")){
			edo="QUINTANA ROO";
		}

		if(edo_cve.equals("24")){
			edo="SAN LUIS POTOSI";
		}
		
		if(edo_cve.equals("25")){
			edo="SINALOA";
		}

		if(edo_cve.equals("26")){
			edo="SONORA";
		}

		if(edo_cve.equals("27")){
			edo="TABASCO";
		}

		if(edo_cve.equals("28")){
			edo="TAMAULIPAS";
		}
		
		if(edo_cve.equals("29")){
			edo="TLAXCALA";
		}
		
		if(edo_cve.equals("30")){
			edo="VERACRUZ";
		}
		
		if(edo_cve.equals("31")){
			edo="YUCATAN";
		}
		
		if(edo_cve.equals("32")){
			edo="ZACATECAS";
		}


		pagweb.setText(eve_www);
		correo1.setText(eve_mail);

		if((eve_hora_ini.equals(null))||(eve_hora_ini.equals("null"))||(eve_hora_ini.equals(""))||(eve_hora_fin.equals(null))
				||(eve_hora_fin.equals("null"))||(eve_hora_fin.equals(""))){
			desc1.setText(eve_nombre+"\n\n"+eve_proveedores+"\n\n"+eve_descripcion+"\n\n"+eve_fec_ini+"\n\n"+eve_fec_fin
		+"\n\n"+eve_lugar+"\n\n"+eve_direccion+"\n\n"+edo+"\n\n"+eve_contacto+"\n\n"+eve_contacto2);
			desc1.setMovementMethod(new ScrollingMovementMethod());
		}else{
			desc1.setText(eve_nombre+"\n\n"+eve_proveedores+"\n\n"+eve_descripcion+"\n\n"+eve_fec_ini+"\n\n"+eve_fec_fin+"\n\n"+eve_hora_ini
					+"\n\n"+eve_hora_fin+"\n\n"+eve_lugar+"\n\n"+eve_direccion+"\n"+edo+"\n\n"+eve_contacto+"\n\n"+eve_contacto2);
			desc1.setMovementMethod(new ScrollingMovementMethod());
		}
		File storagePath = Environment.getExternalStorageDirectory();

		Uri uri=Uri.parse(getApplicationContext().getFilesDir()+"/localdata/"+eve_poster);
		Log.i("URI",""+uri);
		imagen1.setImageURI(uri);

		texto.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0)
			{
				Intent intent = new Intent(EventosDetalles.this,TextoDetallesEvento.class);
				intent.putExtra("query19", ""+eve_descripcion);
				intent.putExtra("query32", ""+eve_nombre);
				intent.putExtra("query33", ""+eve_fec_ini);
				intent.putExtra("query34", ""+eve_fec_fin);
				intent.putExtra("query37", ""+eve_contacto);
				intent.putExtra("query38", ""+eve_contacto2);
				intent.putExtra("query42", ""+eve_hora_ini);
				intent.putExtra("query43", ""+eve_hora_fin);
				intent.putExtra("query50", ""+eve_lugar);
				intent.putExtra("query44", ""+eve_direccion);
				intent.putExtra("query45", ""+eve_colonia);
				intent.putExtra("query46", ""+eve_municipio);
				intent.putExtra("query47", ""+eve_cp);
				intent.putExtra("query48", ""+eve_proveedores);
				intent.putExtra("query49", ""+edo_cve);
				Log.i("LUGAR",""+eve_lugar);
				startActivity(intent);
			}
		});

		tableRow1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0)
			{
				if((eve_www.equals(("null"))||(eve_www.equals(" "))||(eve_www.equals(null)))){
					//				if (!eve_www.startsWith(HTTP) && !eve_www.startsWith(HTTPS)) {
					//					eve_www = HTTP + eve_www;
					//				}
					//				String url = ""+eve_www;
					//				Log.i("pagina web", ""+eve_www);
					//				Intent intent = new Intent(Intent.ACTION_VIEW);
					//				intent.setData(Uri.parse(url));
					//				startActivity(intent);
					Intent intent = new Intent(EventosDetalles.this,PaginawebEventos.class);
					intent.putExtra("query24", ""+eve_www);
					startActivity(intent);
				}
			}
		});


		tableRow2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0)
			{
				final Dialog dialog = new Dialog(EventosDetalles.this);
				dialog.setContentView(R.layout.lista_telefonos);
				dialog.setTitle(R.string.title_TABLEROW);

				final String[] datos = new String[]{eve_tel, eve_tel2, eve_tel3, eve_tel4}; 

				ArrayAdapter<String> adaptador = new ArrayAdapter<String>(EventosDetalles.this,
						android.R.layout.simple_list_item_1, datos);


				listView3 = (ListView)dialog.findViewById(R.id.listViewtel);

				listView3.setAdapter(adaptador);

				listView3.setOnItemClickListener(new OnItemClickListener() {
					@Override
					public void onItemClick(AdapterView<?> a, View v, int position,
							long id) {

						if(eve_tel.equals(datos[position]+ ""))
							try {
								String numero = traerNumero(eve_tel);
								Intent intent1 = new Intent(Intent.ACTION_CALL);
								intent1.setData(Uri.parse("tel:"+numero));
								startActivity(intent1);
							} catch (ActivityNotFoundException activityException) {
							}

						if(eve_tel2.equals(datos[position]+ ""))
							try {
								String numero = traerNumero(eve_tel2);
								Intent intent1 = new Intent(Intent.ACTION_CALL);
								intent1.setData(Uri.parse("tel:"+numero));
								startActivity(intent1);
							} catch (ActivityNotFoundException activityException) {
							}

						if(eve_tel3.equals(datos[position]+ ""))
							try {
								String numero = traerNumero(eve_tel3);
								Intent intent1 = new Intent(Intent.ACTION_CALL);
								intent1.setData(Uri.parse("tel:"+numero));
								startActivity(intent1);
							} catch (ActivityNotFoundException activityException) {
							}

						if(eve_tel4.equals(datos[position]+ ""))
							try {
								String numero = traerNumero(eve_tel4);
								Intent intent1 = new Intent(Intent.ACTION_CALL);
								intent1.setData(Uri.parse("tel:"+numero));
								startActivity(intent1);
							} catch (ActivityNotFoundException activityException) {
							}
						dialog.dismiss();

					}
				});
				dialog.show();
			}
		});


		tableRow3.setOnClickListener(new View.OnClickListener() {
			public void onClick(View arg0)
			{
				if((eve_mail.equals(("null"))||(eve_mail.equals(" "))||(eve_mail.equals(null)))){
					String[] to = {eve_mail};
					Intent emailIntent = new Intent(Intent.ACTION_SEND);
					emailIntent.setData(Uri.parse("mailto:"));
					emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
					emailIntent.putExtra(Intent.EXTRA_CC, "");
					emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
					emailIntent.putExtra(Intent.EXTRA_TEXT, "");
					emailIntent.setType("message/rfc822");
					startActivity(Intent.createChooser(emailIntent, "Email "));
				}
			}
		});


		btnpdfeventos.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				if((eve_pdf.equals(("null"))||(eve_pdf.equals(""))||(eve_pdf.equals(null)))){

					AlertDialog.Builder ad = new AlertDialog.Builder(EventosDetalles.this);
					ad.setMessage("No hay PDF");
					ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
						}
					});
					ad.show();

				}else{
					AlertDialog.Builder builder = new AlertDialog.Builder(EventosDetalles.this);

					builder.setTitle("Aviso");
					builder.setMessage(R.string.title_pdf);
					builder.setPositiveButton("Enviar a Correo", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							String[] to = {};
							Intent emailIntent = new Intent(Intent.ACTION_SEND);
							try {
								InputStream in = new FileInputStream(getApplicationContext().getFilesDir()+"/localdata/"+eve_pdf);
								OutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().toString() +"/informacion.pdf" );
								copyFile(in, out);
					              in.close();
					              in = null;
					              out.flush();
					              out.close();
					              out = null;
							    File fileenvio = new File(Environment.getExternalStorageDirectory().toString() +"/informacion.pdf");
							    emailIntent.setData(Uri.parse("mailto:"));
								emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
								emailIntent.putExtra(Intent.EXTRA_CC, "");
								emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Enviar PDF");
								emailIntent.putExtra(Intent.EXTRA_TEXT, "Quiero que me manden el PDF");
								emailIntent.setType("application/pdf");
								emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(fileenvio));
								startActivity(Intent.createChooser(emailIntent, "Email "));
							} catch (Exception e) {
								e.printStackTrace();
							}
//							//						try{
//							String[] to = {};
//
//							Intent emailIntent = new Intent(Intent.ACTION_SEND);
//							File file = new File(EventosDetalles.this.getFilesDir()+"/localdata/"+eve_pdf);
//							emailIntent.setData(Uri.parse("mailto:"));
//							emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
//							emailIntent.putExtra(Intent.EXTRA_CC, "");
//							emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Enviar PDF");
//							emailIntent.putExtra(Intent.EXTRA_TEXT, "Quiero que me manden el PDF");
//							emailIntent.setType("application/pdf");
//							emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
//							startActivity(Intent.createChooser(emailIntent, "Email "));
//
//							//						}catch(ActivityNotFoundException e){
//							//							Toast.makeText(context, "No ahi PDF", Toast.LENGTH_LONG).show();
//							//						}
						}
					});
					builder.setNegativeButton("Visualizar PDF", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {

							try{
								InputStream in = new FileInputStream(getApplicationContext().getFilesDir()+"/localdata/"+eve_pdf);
								OutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().toString() +"/informacion.pdf" );
								copyFile(in, out);
					              in.close();
					              in = null;
					              out.flush();
					              out.close();
					              out = null;
					              
					              
					              File file = new File(Environment.getExternalStorageDirectory().toString() +"/informacion.pdf");
									if (file.exists()) { 
										Uri path = Uri.fromFile(file); 
										Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
										pdfIntent.setDataAndType(path, "application/pdf");
										pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

										try{
											context.startActivity(pdfIntent);
										}catch(ActivityNotFoundException e){
											Toast.makeText(context, R.string.st_no_application_available_to_view_pdf, Toast.LENGTH_LONG).show();
										}
									}
					              
							}catch(Exception e){
								e.printStackTrace();
							}
//							File file = new File(EventosDetalles.this.getFilesDir()+"/localdata/"+eve_pdf);
//							if (file.exists()) { 
//								//							try{
//								Uri path = Uri.fromFile(file); 
//								Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
//								pdfIntent.setDataAndType(path, "application/pdf");
//								pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//
//								try{
//									context.startActivity(pdfIntent);
//								}catch(ActivityNotFoundException e){
//									Toast.makeText(context, R.string.st_no_application_available_to_view_pdf, Toast.LENGTH_LONG).show();
//								}
//
//							}
						}
					});
					AlertDialog alertDialog = builder.create();
					alertDialog.show();




				}
			}
		});

		calendar.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

				insertCalendario(eve_fec_ini, eve_hora_ini,eve_hora_fin, eve_nombre, eve_descripcion, eve_lugar);
			}

		});
		
		
		
		btnfacebookeve.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
					if((eve_facebook.equals(("null"))||(eve_facebook.equals(""))||(eve_facebook.equals(null)))){

						AlertDialog.Builder ad = new AlertDialog.Builder(EventosDetalles.this);
						ad.setMessage(R.string.title_facebook);
						ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								dialog.cancel();
							}
						});
						ad.show();

					}else{
						try {
							context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
							//				    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<id_here>"));
							Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(eve_facebook));
							startActivity(intent);
						} catch (Exception e) {
							startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"+eve_facebook+"")));
						}
					}
				
				}
		});
		
		
		
		btntwittereve.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if((eve_twitter.equals(("null"))||(eve_twitter.equals(""))||(eve_twitter.equals(null)))){

					AlertDialog.Builder ad = new AlertDialog.Builder(EventosDetalles.this);
					ad.setMessage(R.string.title_TWITTER);
					ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int id) {
							dialog.cancel();
						}
					});
					ad.show();

				}else{
					try {
						Intent intent = new Intent(Intent.ACTION_VIEW,
								Uri.parse("twitter://user?screen_name= "+eve_twitter+""));
						startActivity(intent);

					}catch (Exception e) {
						startActivity(new Intent(Intent.ACTION_VIEW,
								Uri.parse("https://twitter.com/#!/"+eve_twitter+""))); 
					} 
				}
				}
		});

	}


	private String traerNumero(String eve_tel12) {
		char[] chararray = eve_tel12.toCharArray();
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i<chararray.length; i++){
			if((chararray[i] == '0')||(chararray[i] == '1')||(chararray[i] == '2')||(chararray[i] == '3')||(chararray[i] == '4')
					||(chararray[i] == '5')||(chararray[i] == '6')||(chararray[i] == '7')||(chararray[i] == '8')||(chararray[i] == '9')){
				builder.append(chararray[i]);
			}
		}
		return builder.toString();
	}

//	public void BtnFcebookEvento(View view) {
//
//		if((eve_facebook.equals(("null"))||(eve_facebook.equals(""))||(eve_facebook.equals(null)))){
//
//			AlertDialog.Builder ad = new AlertDialog.Builder(this);
//			ad.setMessage("No hay p�gina de Facebook");
//			ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
//				public void onClick(DialogInterface dialog, int id) {
//					dialog.cancel();
//				}
//			});
//			ad.show();
//
//		}else{
//			Intent intent = new Intent(EventosDetalles.this,PaginaFacebook.class);
//			intent.putExtra("query22", ""+eve_facebook);
//			startActivity(intent);
	
			//		if (!eve_facebook.startsWith(HTTP) && !eve_facebook.startsWith(HTTPS)) {
			//			eve_facebook = HTTP + eve_facebook;
			//		}
			//		
			//		String url = ""+eve_facebook;
			//		Log.i("pagina web", ""+eve_facebook);
			//		Intent intent = new Intent(Intent.ACTION_VIEW);
			//		intent.setData(Uri.parse(url));
			//		startActivity(intent);

//		}
	
		//		Uri uri = Uri.parse(eve_facebook);
		//		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		//		startActivity(intent);
//	}

	
//	public void BtnTwitterEvento(View view) {
//
//		if((eve_twitter.equals(("null"))||(eve_twitter.equals(""))||(eve_twitter.equals(null)))){
//
//			AlertDialog.Builder ad = new AlertDialog.Builder(this);
//			ad.setMessage("No hay p�gina de Twitter");
//			ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
//				public void onClick(DialogInterface dialog, int id) {
//					dialog.cancel();
//				}
//			});
//			ad.show();
//
//		}else{
//			Intent intent = new Intent(EventosDetalles.this,PaginaTwitter.class);
//			intent.putExtra("query23", ""+eve_twitter);
//			startActivity(intent);

			//		if (!eve_twitter.startsWith(HTTP) && !eve_twitter.startsWith(HTTPS)) {
			//			eve_twitter = HTTP + eve_twitter;
			//		}
			//		String url = ""+eve_twitter;
			//		Log.i("pagina web", ""+eve_twitter);
			//		Intent intent = new Intent(Intent.ACTION_VIEW);
			//		intent.setData(Uri.parse(url));
			//		startActivity(intent);

//		}
		//		Uri uri = Uri.parse(eve_twitter);
		//		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		//		startActivity(intent);
//	}


	public void btnmapaEvento(View view) {

		if((eve_lat.equals(("null"))||(eve_lat.equals(""))||(eve_lat.equals(null))
				||(eve_lng.equals(("null"))||(eve_lng.equals(""))||(eve_lng.equals(null))))){

			AlertDialog.Builder ad = new AlertDialog.Builder(this);
			ad.setMessage("No hay Mapa");
			ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					dialog.cancel();
				}
			});
			ad.show();

		}else{
			Intent intent1 = new Intent(EventosDetalles.this,MapaEventos.class);
			intent1.putExtra("query29", ""+eve_lat);
			Log.i("latitud0",""+eve_lat);
			intent1.putExtra("query30", ""+eve_lng);
			startActivity(intent1);
		}
	}


	private void copyFile(InputStream in, OutputStream out) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while((read = in.read(buffer)) != -1){
          out.write(buffer, 0, read);
        }
    }

	public void insertCalendario(String fecha, String horaini,String horafin, String titulo,
			String descripcion, String ubicacion) {
		try {
			int diaini, mesini, anioini, diafin, mesfin, aniofin;
			String[] fini = eve_fec_ini.replace("/", "-").split("-");
			String[] ffin = eve_fec_fin.replace("/", "-").split("-");

			anioini = Integer.parseInt(fini[0]);
			Log.i("AÑO", ""+anioini);
			mesini = Integer.parseInt(fini[1]);
			Log.i("MES", ""+mesini);
			diaini = Integer.parseInt(fini[2]);
			Log.i("DIA", ""+diaini);

			aniofin = Integer.parseInt(ffin[0]);
			Log.i("AÑO", ""+aniofin);
			mesfin = Integer.parseInt(ffin[1]);
			Log.i("MES", ""+mesfin);
			diafin = Integer.parseInt(ffin[2]);
			Log.i("DIA", ""+diafin);


			//			Calendar beginTime = Calendar.getInstance();
			//			beginTime.set(Integer.parseInt(eve_fec_ini), 0, 0, Integer.parseInt(eve_hora_ini), 0);
			//			long startMillis = beginTime.getTimeInMillis();
			//			Calendar endTime = Calendar.getInstance();
			//			endTime.set(Integer.parseInt(eve_fec_fin), 0, 0, Integer.parseInt(eve_hora_fin), 0);
			//			long endMillis = endTime.getTimeInMillis();

			Calendar beginTime = Calendar.getInstance();
			beginTime.set(anioini, mesini, diaini, 0, 0);
			long startMillis = beginTime.getTimeInMillis();
			Calendar endTime = Calendar.getInstance();
			endTime.set(aniofin, mesfin, diafin, 0, 0);
			long endMillis = endTime.getTimeInMillis();


			Intent i = new Intent();
			i.setType("vnd.android.cursor.item/event");
			i.putExtra("title", titulo);
			i.putExtra("description", descripcion);
			i.putExtra("eventLocation", ubicacion);
			i.putExtra("beginTime", startMillis);
			i.putExtra("endTime", endMillis);


			//			intent.putExtra("query19", ""+eve_descripcion);
			//			intent.putExtra("query32", ""+eve_nombre);
			//			intent.putExtra("query33", ""+eve_fec_ini);
			//			intent.putExtra("query34", ""+eve_fec_fin);
			//			intent.putExtra("query42", ""+eve_hora_ini);
			//			eve_lugar = extras1.getString("query36");;

			i.setAction(Intent.ACTION_EDIT);
			startActivity(i);

		} catch (Exception ex) {
			ex.printStackTrace();
			AlertDialog.Builder ad = new AlertDialog.Builder(this);
			ad.setMessage("Error al ingresar el evento al calendario");
			ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int id) {
					dialog.cancel();
				}
			});
			ad.show();
		}

	}
}